<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>员工工时统计</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="departName"
					idField="departID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>姓名：</span>
								<div id="txtUserID" class="mini-autocomplete" style="width:150px;" popupWidth="200" textField="userName" valueField="userID">
									<div property="columns">
										<div header="姓名" field="userName" width="40"></div>
										<div header="编号" field="workNo"></div>
									</div>
								</div>
								<span>日期从：</span>
								<input id="calendarDate_from" name="calendarDate_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<span>到：</span>
								<input id="calendarDate_to" name="calendarDate_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="doSearch()">查询</a>
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="output()">导出</a>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" allowResize="true" multiSelect="true">
				</div>
			</div>
		</div>
	</div>

</body>

<script type="text/javascript">
	miniInit();

	var tree = mini.get("pageTree");
	http.get('/sys/depart/list.do', function (page) {
		tree.loadData(page);
	});
	var editNode = null; // 当前编辑的节点
	/*********************************************************
	 * 左侧目录树的鼠标点击事件
	 *********************************************************/
	tree.on("nodedblclick", function (e) {
		// debugger
		editNode = e.node;
		http.get('/sys/depart/list.do?departID=' + editNode.departID, function (page) {
			tree.addNodes(page, editNode);
			tree.expandNode(editNode);
		});
	});

	var txtUserID = mini.get("txtUserID");
	txtUserID.setName("userID");
	txtUserID.set({
		url: http.getUrl("/user/page.do")
	});

	// 设置截止日期至今天
	var date = new Date();
	mini.get("calendarDate_to").setValue(date);
	date.setDate(date.getDate() - 5);
	mini.get("calendarDate_from").setValue(date);

	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid");

	function doSearch() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
		} else {
			data["departID"] = 'ROOT';
		}
		var columns = [{
			type: "indexcolumn"
		}, {
			field: "departName",
			width: 100,
			headerAlign: "center",
			header: "部门名称"
		}, {
			field: "userName",
			width: 100,
			headerAlign: "center",
			header: "员工名称"
		}, {
			field: "workTime",
			width: 100,
			headerAlign: "center",
			header: "工作时长"
		}, {
			field: "overTime",
			width: 100,
			headerAlign: "center",
			header: "加班时长"
		}, {
			field: "applyTime",
			width: 100,
			headerAlign: "center",
			header: "请假时长"
		}];
		http.post("/project/static/user/list.do", data, function (page) {
			if (page.success) {
				if (page.dataMap.title) {
					var title = page.dataMap.title;
					for (var i = 0; i < title.length; i++) {
						columns.push({
							field: title[i],
							width: 100,
							headerAlign: "center",
							header: title[i]
						});
					}
				}
				datagrid.set({
					data: page.data,
					columns: columns
				});
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}


	function output() {
		mini.mask({
			el: document.body,
			cls: 'mini-mask-loading',
			html: '数据处理中...'
		});
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
			// data["departName"] = node.departName;
		}
		// debugger
		data["orderby"] = ["calendarDate,desc"];
		http.post("/project/static/user/outPut.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				mini.alert("数据处理成功，准备下载!", "提示", null);
				var url = http.getUrl("/file/any/getFile.do");
				jQuery('<form action="' + url + '"method=post">' + // action请求路径及推送方法
					'<input type="text" name="url" value="' + page.dataMap.filename + '"/>' + // 文件路径
					'</form>')
					.appendTo('body').submit().remove();
			} else {
				mini.alert(page.message, "提示", null);
			}
		});
	}
</script>

</html>